'''

@author: wyndem
@Emil:   wyndem@qq.com
@FileName: redis_utils.py
@Time: 2018/11/15 14:02
@Software: PyCharm
@Description: 

'''
import random
import time

import redis

from novel.config.rules import RULES

rcon = redis.StrictRedis(host='47.107.159.28', db=10)
# r1 = redis.Redis(host='47.107.159.28', port=6379,db=9)
r1 = rcon



def service(func):
    def decorator(*args, **kw):
        t = random.randint(1, 5) * random.uniform(0.1, 0.5)
        time.sleep(t)
        m = r1.get(str(*args))
        if m == None:
            r1.set(str(*args), True, ex=300)
            return func(*args, **kw)

    return decorator



if rcon.exists('web'):
    rcon.delete('web')

urls=[]
for r in RULES:
    urls.append(r)
rcon.set("web",urls)